Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Feat/id source #242

Merged
merged 6 commits into from
Dec 30, 2021
Merged

Conversation

mvergez
Copy link
Contributor

@mvergez mvergez commented Oct 6, 2021

Objectif

Ajout d'un champ id_source_synthese dans la table t_imports pour faire un lien avec la table t_sources du schéma gn_synthese.

Implémentation

  • Ajout d'une colonne et une contrainte associée dans t_imports comme suit :

    ALTER table gn_imports.t_imports add column id_source_synthese int4 null;
    ALTER table only gn_imports.t_imports
        ADD CONSTRAINT fk_gn_imports_t_import_id_source_synthese FOREIGN KEY (id_source_synthese) REFERENCES gn_synthese.t_sources(id_source) ON UPDATE SET NULL ON DELETE CASCADE;
  • En attendant un script de "remplissage" des id_source_synthese des imports existants (voir ci-après), ajout d'une condition (https://github.com/mvergez/gn_module_import/blob/2920471a617fc730bb2aaeb8726bf1aadfe0f27b/backend/db/models.py#L99) pour calculer l'id_source s'il n'est pas disponible dans la table t_imports

  • Ajout d'un script sql permettant de compléter les id_source_synthese des imports existants

Closes #201

Maxime Vergez added 2 commits September 27, 2021 17:57
Add a foreign key to create a "link" from t_imports to t_sources
with the id_source. Changed the model and update the finalize
import to update the id_source_synthese in t_imports
Add possibility to compute the id_source when not present in the
database
Add DELETE CASCADE on the foreign key
Need to add migration
@DonovanMaillard
Copy link
Collaborator

On fera un script pour renseigner l'id_source dans la t_imports avant de sortir une release, de cette manière on pourra simplifier le code en retirant ta fonction. Lors de la migration vers la nouvelle version, un id_source sera forcément présent dans le nouveau champs, sauf anomalie dans la BDD (imports avortés, données supprimées de la synthèse etc).

@DonovanMaillard
Copy link
Collaborator

Le script d'update à fournir pour éviter une fonction "temporaire" ;)

UPDATE gn_imports.t_imports
SET id_source_synthese = s.id_source
FROM gn_synthese.t_sources s
WHERE s.name_source='Import(id='||id_import||')'

Maxime Vergez added 2 commits December 6, 2021 09:12
Named it "toDev" since no target version has been defined yet
Tested with the 1.1.2toDev.sql and it seems to work
@mvergez
Copy link
Contributor Author

mvergez commented Dec 6, 2021

Ajout de ce script avec la création de la table dans un script de migration qu'il faudra renommer quand on mergera sur la master.

@mvergez
Copy link
Contributor Author

mvergez commented Dec 6, 2021

Pour l'instant je laisse la solution temporaire. C'est juste une condition qui regarde si l'id_source_synthèse est bien présent dans la base de données sinon il va le chercher dans t_sources comme c'était fait avant.

Maxime Vergez added 2 commits December 30, 2021 10:44
Since there will be a migration script that will fill in the
id_source_synthese, there is no need to check
@DonovanMaillard DonovanMaillard merged commit f31209c into PnX-SI:project-FLA_NS Dec 30, 2021
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants